<?php
/**
 * Created by PhpStorm.
 * Author: ljz
 * Date: 2023/5/10
 * Time: 11:29
 */

namespace App\backend\models;


use App\common\models\BaseModel;
use Illuminate\Support\Facades\DB;

/**
 * Class OrderModel
 * @package app\common\models
 */
class AreaModel extends BaseModel
{
    const table = 'area';

    public function __construct() {

    }

    /**
     * 查询字段规则
     *
     * @return array
     */
    static public function rules()
    {
        return [];
    }

    /**
     * 字段验证返回错误信息
     *
     * @return array
     */
    static public function message()
    {
        return [];
    }

    /**
     * 数据库 - 查询城市
     * @param $id int //城市ID
     * @return array
     */
    static public function cityInfo($id)
    {
        $addres_name = '暂无数据';

        if (empty($id)) {
            return $addres_name;
        }

        $part_data = DB::table('area')->where('id', $id)->first();

        if ($part_data && $part_data->level != 1) {
            $part_sec_data = DB::table('area')->where('id', $part_data->parentid)->first();
            $addres_name = $part_sec_data->areaname.'-'.$part_data->areaname;
            if ($part_sec_data && $part_sec_data->level != 1) {
                $part_tr_data = DB::table('area')->where('id', $part_sec_data->parentid)->first();
                $addres_name = $part_tr_data->areaname.'-'.$addres_name;
            }
        } else {
            $addres_name = $part_data->areaname;
        }

        return $addres_name;
    }

}
